package util;

import java.util.Timer;
import java.util.TimerTask;

public class Cronometro {
	private static final Cronometro INSTANCE = new Cronometro();
	private Timer timer;
	private Reminder r;
	private int timeInSeconds;

	private Cronometro() {
	}
	
	public static Cronometro getInstance() {
		return INSTANCE;
	}
	
	public class Reminder{
		public Reminder(int seconds) {
			timer = new Timer();
			timeInSeconds = seconds;
			while(seconds > 0){
				timer.schedule(new RemindTask(), 1000);
				seconds--;
				timeInSeconds--;
			}
		}
		
		public class RemindTask extends TimerTask {
			public void run() {
				timer.cancel(); //Terminate the timer thread
			}
		}
	}
	
	public void starTime(int seconds){
		r = new Reminder(seconds);
	}

	public int getTimeInSeconds() {
		return timeInSeconds;
	}

	public void setTimeInSeconds(int timeInSeconds) {
		this.timeInSeconds = timeInSeconds;
	}
}